package cn.consult.controller.sys.apartment;

import cn.consult.common.api.CommonPage;
import cn.consult.common.api.CommonResult;
import cn.consult.sys.entity.TWeGatewayConfig;
import cn.consult.sys.service.TWeGatewayConfigService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/**
 * @ Author：周xx
 * @ Date：2024-04-09-9:13
 * @ Version：1.0
 * @ Description：水电网关配置
 */

@Api(tags = "公寓管理 > 水电网关配置")
@RestController
@RequestMapping("/apartment/wegateway")
public class TWeGatewayConfigController {

    @Autowired
    TWeGatewayConfigService tWeGatewayConfigService;


    @ApiOperation("selectPage =>  分页查询网关信息")
    @GetMapping("/selectPage")
    public CommonResult selectPage(@RequestParam Map<String, Object> params) {
        IPage<TWeGatewayConfig> page = tWeGatewayConfigService.selectPage(params);
        return CommonResult.success(CommonPage.restPage(page));
    }

    @ApiOperation("addGateway =>  添加网关信息")
    @PostMapping("/addGateway")
    public CommonResult addGateway(@RequestBody TWeGatewayConfig tWeGatewayConfig) {
        tWeGatewayConfig.setCreateTime(LocalDate.now().toString());
        tWeGatewayConfig.setJoinTime(LocalDate.now().toString());
        tWeGatewayConfig.setGatewayStatus(1);
        boolean save = tWeGatewayConfigService.save(tWeGatewayConfig);
        if (save) {
            return CommonResult.success(save);
        }
        return CommonResult.failed();
    }

    @ApiOperation("updateGateway =>  修改网关信息")
    @PutMapping("/updateGateway")
    public CommonResult updateGateway(@RequestBody TWeGatewayConfig tWeGatewayConfig) {
        tWeGatewayConfig.setUpdateTime(LocalDate.now().toString());
        boolean save = tWeGatewayConfigService.updateById(tWeGatewayConfig);
        if (save) {
            return CommonResult.success(save);
        }
        return CommonResult.failed();
    }

    @ApiOperation("deleteGateway =>  删除网关信息")
    @DeleteMapping("/deleteGateway/{id}")
    public CommonResult deleteGateway(@PathVariable Long id) {
        boolean save = tWeGatewayConfigService.removeById(id);
        if (save) {
            return CommonResult.success(save);
        }
        return CommonResult.failed();
    }

    @ApiOperation("getGatewayAll =>  拿到所有网关信息")
    @GetMapping("/getGatewayAll")
    public CommonResult getGatewayAll() {
        List<TWeGatewayConfig> list = tWeGatewayConfigService.list();
        return CommonResult.success(list);
    }
}
